const path = require('path');

module.exports = {
    cacheId: 'webpack-pwa-2', // 设置前缀
    cleanupOutdatedCaches: true, // 删除旧的预缓存
    skipWaiting: true,
    clientsClaim: true,
    globDirectory: path.resolve(__dirname, '../'),
    globPatterns: ["**\/*.{js,css,html,ttf}"],
    sourcemap: false,
    mode: 'development', // 生成sw文件的模式
    swDest: path.resolve(__dirname , 'service-worker.js'), // 默认 service-worker.js
    // exclude: ['service-wroker.js'], // 排除的文件
    runtimeCaching: [
        {
            urlPattern: /^http:\/\/juheimg.oss-cn-hangzhou.aliyuncs.com/,
            handler: 'NetworkFirst', // 网络优先
            options: {
                cacheName: 'images-cache',
                expiration: {
                    maxEntries: 20, // 针对改类型的缓存的最大数量，超过替换
                },
            },
        },
        {
            urlPattern: /^http:\/\/localhost:3030\//,
            handler: 'NetworkFirst', // 网络优先
            options: {
                cacheName: 'api-cache',
                expiration: {
                    maxAgeSeconds: 10 // 过期时间，/秒
                },
            },
        }
    ]
}